package com.samebuilding.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.samebuilding.dao.UserDataDAO;
import com.samebuilding.domain.UserData;

public class UserDataDAOImpl extends HibernateDaoSupport implements UserDataDAO {

	public void save(UserData ud) {
		this.getHibernateTemplate().save(ud);

	}

	public void update(UserData ud) {
		this.getHibernateTemplate().update(ud);

	}

	public UserData find(int userNo) {
		List list=this.getHibernateTemplate().find("from UserData as ud where ud.userNo=?",userNo);
		if(list!=null&&list.size()>0){
			return (UserData)list.get(0);
		}
		return null;
	}

	public void addMoney(int userNo, int money) {
		UserData ud=this.find(userNo);
		int m=ud.getMoney();
		m+=money;
		ud.setMoney(m);
		this.update(ud);
		
	}

	public boolean bigThanMoney(int userNo, int money) {
		UserData ud=this.find(userNo);
		int m=ud.getMoney();
		if(m>=money){
			return true;
		}
		return false;
	}

}
